package com.tedu.controller;

import com.tedu.pojo.Information;
import com.tedu.pojo.Topic;
import com.tedu.servies.TopicServies;
import com.tedu.servies.InforNewsServies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.xml.ws.RequestWrapper;
import java.util.List;

/**
 * 控制层方法
 * 处理用户请求
 */
@Controller   // 把该组件声明为一个controller，处理用户的请求
public class IndexController {

    //要数据  服务
    @Autowired
    TopicServies topicServies;
    @Autowired
    InforNewsServies inforNewsServies;


    /**
     * 显示项目首页信息
     * @return
     */
    @RequestMapping("/")
    public String toIndex(Model model)
    {
        System.out.println("用户正在访问首页");
        //调用服务层方法，获取全部信息类型数据
        List<Topic> data = topicServies.getAllTopic();
        //添加到servlet的域中
        model.addAttribute("alltopic",data);
        System.out.println(data);

        //获取10个随机的党建信息类型数据
        List<Topic> topic = topicServies.getTopic();
        model.addAttribute("topic",topic);

        //获取最新的10条党建要闻
        List<Information> informationList = inforNewsServies.getInformationByTypeTen(1,10);
        //发送到页面
        model.addAttribute("informationList",informationList);

        //获取最新的一条视频新闻
        List<Information> informationList2 = inforNewsServies.getInformationByTypeTen(2, 1);
        model.addAttribute("informationList2",informationList2.get(0));

        //获取5条最新的学习园地数据
        List<Information> informationList3 = inforNewsServies.getInformationByTypeTen(3, 5);
        model.addAttribute("informationList3",informationList3);

        //获取最新5条理论强党数据
        List<Information> informationList4 = inforNewsServies.getInformationByTypeTen(4, 5);
        model.addAttribute("informationList4",informationList4);

        //获取最新5条  党建评论数据
        List<Information> informationList5 = inforNewsServies.getInformationByTypeTen(5, 5);
        model.addAttribute("informationList5",informationList5);

        List<Information> informationList6 = inforNewsServies.getInformationByTypeTen(6, 5);
        model.addAttribute("informationList6",informationList6);

        List<Information> informationList7 = inforNewsServies.getInformationByTypeTen(7, 5);
        model.addAttribute("informationList7",informationList7);

        List<Information> informationList8 = inforNewsServies.getInformationByTypeTen(8, 5);
        model.addAttribute("informationList8",informationList8);

        List<Information> informationList9 = inforNewsServies.getInformationByTypeTen(9, 5);
        model.addAttribute("informationList9",informationList9);

        List<Information> informationList10 = inforNewsServies.getInformationByTypeTen(10, 5);
        model.addAttribute("informationList10",informationList10);

        List<Information> informationList11 = inforNewsServies.getInformationByTypeTen(11, 5);
        model.addAttribute("informationList11",informationList11);

        List<Information> informationList12 = inforNewsServies.getInformationByTypeTen(12, 5);
        model.addAttribute("informationList12",informationList12);

        List<Information> informationList13 = inforNewsServies.getInformationByTypeTen(13, 5);
        model.addAttribute("informationList13",informationList13);

        List<Information> informationList14 = inforNewsServies.getInformationByTypeTen(14, 5);
        model.addAttribute("informationList14",informationList14);

        List<Information> informationList15 = inforNewsServies.getInformationByTypeTen(15, 5);
        model.addAttribute("informationList15",informationList15);

        List<Information> informationList16 = inforNewsServies.getInformationByTypeTen(16, 5);
        model.addAttribute("informationList16",informationList16);

        List<Information> informationList17 = inforNewsServies.getInformationByTypeTen(17, 5);
        model.addAttribute("informationList17",informationList17);

        //需要页面发送数据   转发
        return "forward:/index.jsp";
    }


}



